package util

import (
	"bytes"
	"path/filepath"
	"runtime"
	"strconv"
)

//ReadCurrStack read curr method stack info
func ReadCurrStack() string {
	_, file, line, ok := runtime.Caller(1)
	buffer := bytes.Buffer{}
	if !ok {
		return ""
	}
	buffer.WriteString(filepath.Base(file))
	buffer.WriteString(":")
	buffer.WriteString(strconv.Itoa(line))
	return buffer.String()
}

//ReadParentStack read parent method stack info
func ReadParentStack() string {
	_, file, line, ok := runtime.Caller(2)
	buffer := bytes.Buffer{}
	if !ok {
		return ""
	}
	buffer.WriteString(filepath.Base(file))
	buffer.WriteString(":")
	buffer.WriteString(strconv.Itoa(line))
	return buffer.String()
}
